package com.example.flowermall.entity;
import lombok.Data;
import org.springframework.http.HttpStatus;

import java.util.HashMap;

/**
 * @author 小鑫
 * @description:
 * @date 2023/3/23 21:17
 */
@Data
public class Result extends HashMap<String,Object> {

    /** 状态码 */
    public static final String CODE_TAG = "code";

    /** 返回内容 */
    public static final String MSG_TAG = "msg";

    /** 数据对象 */
    public static final String DATA_TAG = "data";

    public Result(){

    }
    public Result(String  msg){
        super.put(MSG_TAG,msg);
    }

    public Result(int code, String msg){
        super.put(CODE_TAG,code);
        super.put(MSG_TAG,msg);
    }


    public Result(int code, String msg, Object data){
        super.put(CODE_TAG,code);
        super.put(MSG_TAG,msg);
        super.put(DATA_TAG,data);
    }

    public static Result success(Object data){
        return Result.success("操作成功",data);
    }

    public static Result success(){
        return Result.success("操作成功");
    }
    public static Result success(String msg){
        return Result.success(msg, null);
    }

    public static Result success(String msg,Object data){
        return new Result(20000,msg,data);
    }

    public static Result error(String msg){
        return Result.error(msg,null);
    }

    public static Result error(int code,String msg){
        return new Result(code,msg,null);
    }

    public static Result error(String msg,Object data){
        return new Result(20002,msg,null);
    }

}
/*import lombok.AllArgsConstructor;
import lombok.Data;

@Data
@AllArgsConstructor
public class Result<T>{
    private  Integer code;
    private  String message;
    private T data;
    public static <T> Result<T> success(){
        return  new Result<>(20000, "success",null );
    }
    public static <T> Result<T> success(T data){
        return  new Result<>(20000, "success",data );
    }
    public static <T> Result<T> success(T data,String message){
        return  new Result<>(20000, message,data );
    }
    public static <T> Result<T> success(String message){
        return  new Result<>(20000, message,null );
    }
    public static <T> Result<T> fail(){
        return  new Result<>(20001, "fail",null );
    }
    public static <T> Result<T> fail(Integer code){
        return  new Result<>(code, "fail",null );
    }
    public static <T> Result<T> fail(Integer code,String message){
        return  new Result<>(code, message,null );
    }
    public static <T> Result<T> fail(String message) {
        return new Result<>(20001, message, null);
    }

}*/
